package com.flycent.hqhs.ui;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.annotation.view.ViewInject;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.flycent.hqhs.App;
import com.flycent.hqhs.R;

/**
 * @author fbl
 * 发票信息
 */
public class ChoiceInvoiceInformationActivity extends BackableTitleBarActivity{
	@ViewInject(id = R.id.invoice_sure_but,click = "butClick") Button mSureBut;
	@ViewInject(id = R.id.invoice_taitou_edit) EditText mEdit;
	@ViewInject(id = R.id.invoice_detail_lin) LinearLayout mInvoiceDetailLin;
	@ViewInject(id = R.id.choice_invoice_radio0,click = "butClick") RadioButton mRadio0;
	@ViewInject(id = R.id.choice_invoice_radio1,click = "butClick") RadioButton mRadio1;
	@ViewInject(id = R.id.choice_invoice_radioGroup) RadioGroup mRadioGroup;

	private boolean isInvoice;
	private String invoiceTitle = "";


	@Override
	protected void onCreate(Bundle savedInstance) {
		super.onCreate(savedInstance);
		setContentView(R.layout.activity_choice_invoice_information);
		FinalActivity.initInjectedView(this);
		getTitleBar().setTitle(R.string.title_choise_invoice_information_method);
		isInvoice = getIntent().getBooleanExtra("isInvoice", true);
		invoiceTitle  = getIntent().getStringExtra("invoiceTitle");

		if(isInvoice ){
			mRadioGroup.check(R.id.choice_invoice_radio1);
			mInvoiceDetailLin.setVisibility(View.VISIBLE);
			mEdit.setText(invoiceTitle);
		}else {
			mRadioGroup.check(R.id.choice_invoice_radio0);
			mInvoiceDetailLin.setVisibility(View.GONE);
		}


	}
	public void butClick(View v){
		// 确认
		if(v == mSureBut){
			if(isInvoice){
				invoiceTitle = getText(mEdit);
				if( invoiceTitle == null || "".equals(invoiceTitle)  ){
					App.showShortToast("发票抬头信息不能为空");
					return;
				}
			}else {
				invoiceTitle = "";
			}
			
			Intent intent = new Intent();
			intent.putExtra("isInvoice", isInvoice);
			intent.putExtra("invoiceTitle", invoiceTitle);
			setResult(400,intent);
			finish();


		}
		// 不开发票
		if(v == mRadio0){
			mInvoiceDetailLin.setVisibility(View.GONE);
			isInvoice = false;
		}
		// 开发票
		if(v == mRadio1){
			mInvoiceDetailLin.setVisibility(View.VISIBLE);
			isInvoice = true;
		}

	}

}
